|
In computer science, a calling convention is an implementation-level (low-level) scheme for how subroutines receive parameters from their caller and how they return a result. Differences in various implementations include where parameters, return values and return addresses are placed, and how the tasks of preparing for a function call and cleaning up the environment afterward are divided between the caller and the callee. Calling conventions may be related to a particular programming language's evaluation strategy but most often are not considered part of it (or vice versa), as the evaluation strategy is usually defined on a higher abstraction level and seen as a part of the language rather than as a low-level implementation detail of a particular language's compiler. == Overview == Calling conventions may differ in: * Where parameters, return values and return addresses are placed (in registers, on the call stack, a mix of both, or in other memory structures) * The order in which actual arguments for formal parameters are passed (or the parts of a large or complex argument) * How a (possibly long or complex) return value is delivered from the callee back to the caller (on the stack, in a register, or within the heap) * How the task of setting up for and cleaning up after a function call is divided between the caller and the callee * Whether and how metadata describing the arguments is passed * Where the previous value of the frame pointer is stored, which is used to restore the frame pointer when the routine ends (in the stack frame, or in some register) * Where any static scope links for the routine's non-local data access are placed (typically at one or more positions in the stack frame, but sometimes in a general register, or, for some architectures, in special-purpose registers) * How local variables are allocated can sometimes also be part of the calling convention (when the caller allocates for the callee) In some cases, differences also include the following: * Conventions on which registers may be directly used by the callee, without being preserved (otherwise regarded as an ABI detail) * Which registers are considered to be volatile and, if volatile, need not be restored by the callee (often regarded as an ABI detail) Although ''some'' languages actually may specify this partially in the programming language specification (or in some pivotal implementation), different implementations of such languages (i.e. different compilers) may typically still use various calling conventions, often selectable. Reasons for this are performance, frequent adaptation to the conventions of other popular languages (with or without technical reasons), and restrictions or conventions imposed by various "platforms" (combinations of CPU architectures and operating systems). This must be considered when combining modules written in multiple languages, or when calling operating system or library APIs from a language other than the one in which they are written; in these cases, special care must be taken to coordinate the calling conventions used by caller and callee. Even a program using a single programming language may use multiple calling conventions, either chosen by the compiler, for code optimization, or specified by the programmer. CPU architectures always have more than one possible calling convention. With many general-purpose registers and other features, the potential number of calling conventions is large, although some architectures are formally specified to use only one calling convention, supplied by the architect. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Calling convention」の詳細全文を読む スポンサード リンク
|